#ifndef STATEMACHINE_HPP
#define STATEMACHINE_HPP

#include <SFML/Graphics.hpp>
#include <fstream>
#include <string>
#include <vector>
#include "GameState.hpp"

namespace OForce_Mode {

// titleMode introduces and sets up the game.
// townMode occurs when navigating towns. It needs to handle chests, NPCs
//   shops, scripted events
// battleMode is the portion where battles occur. This is a turn based strategy
//   mode. It needs to keep track of battle characters stats, movement,
//   treasure chests and scripted events
// attackMode exists on top of battleMode and simply shows battle scenes as
//   as well as calculation of stat changes due to battle actions
// worldMode is a lot like townMode but it will need to handle much larger
//   areas. Ideally this will be done through adding and removing of world
//   elements as the player moves.
// menuMode handles the game menus
// cutsceneMode handles cutscenes (if there are any)
enum GAME_STATE{titleMode, townMode, battleMode, attackMode, navigationMode,
	menuMode, cutsceneMode};

// Should this be singleton?
class StateMachine {
public:
  static StateMachine *Instance();
  static void KillInstance();
  ~StateMachine();
  // Update the Game
  void update();// {mCurrentState->update();}
  // Draw next frame
  void draw();
//  void characterAction() {mCurrentState->characterAction();}
  void activate(std::string stateName);
  void deactivate(std::string stateName);
  void change(std::string newState, bool holdState);
  void add(State *state);
  void setCurrentState(State *state) {mCurrentState = state;}
  void pop();
  void popAll();
  void setGameState(GAME_STATE gs) {mGameState = gs;}
  GAME_STATE getGameState() {return mGameState;}
  void startFading();
private:
  StateMachine();
  // TODO put fading routines in here instead of in the mode itself
  bool mFade;
  bool isFading;
  float fadeInTimer;
  float fadeTimer;
  sf::RectangleShape fadeRect;
  bool changeState;
  int nPop;
  static StateMachine *m_pInstance;
  GAME_STATE mGameState;
  State *mCurrentState;
  // Should I use a vector or a map? Probably I won't have more than a couple
  // game states at a time and they will be ordered regularly so a vector
  // should be good.
  std::vector<State *> vStateStack;
  std::vector<State *> vPushBuffer;
}; // class GameMode

}; // namespace OForce_Mode



#endif
